import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getwidget/components/carousel/gf_carousel.dart';
import 'package:getwidget/components/carousel/gf_items_carousel.dart';

import '../controllers/gfcarousel_controller.dart';

class GfcarouselView extends GetView<GfcarouselController> {
  final List<String> imageList = [
    "assets/images/dh1.jpg",
    "assets/images/dh2.jpg",
    "assets/images/dh3.jpg",
    "assets/images/dh4.jpg",
    "assets/images/dh5.jpg",
    "assets/images/dh6.jpg"
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('轮播图'),
        centerTitle: true,
      ),
      body: Container(
        margin: EdgeInsets.all(10),
        child: ListView(
          children: [
            GFCarousel(
              items: imageList.map((url) {
                return Container(
                  margin: EdgeInsets.all(8.0),
                  child: ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(5.0)),
                    child: Image.asset(
                      url,
                      fit: BoxFit.cover,
                      width: Get.width
                    ),
                  ),
                );
              }).toList(),
              autoPlay: true,
              autoPlayInterval: Duration(seconds: 3),
              onPageChanged: (index) {
                controller.count.value = index;
              },
            ),

            GFCarousel(
              items: imageList.map((url) {
                return Container(
                  margin: EdgeInsets.all(8.0),
                  child: ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(5.0)),
                    child: Image.asset(
                      url,
                      fit: BoxFit.cover,
                      width: Get.width
                    ),
                  ),
                );
              }).toList(),
              viewportFraction: 1.0,
              pagination: true,
              autoPlay: true,
              autoPlayInterval: Duration(seconds: 5),
              scrollDirection: Axis.vertical,
              onPageChanged: (index) {
                controller.count.value = index;
              },
            ),

            GFItemsCarousel(
              rowCount: 3,
              children: imageList.map((url) {
                return Container(
                  margin: EdgeInsets.all(5.0),
                  child: ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(5.0)),
                  child:
                    Image.asset(
                      url, 
                      fit: BoxFit.cover, 
                      width: Get.width
                    ),
                  ),
                );
              }).toList(),
            )
          ],
        )
        
        
      ),
    );
  }
}
